package com.hy.example.shared.exception;


import com.hy.example.common.api.result.ApiResult;
import feign.codec.DecodeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@Slf4j
@RestControllerAdvice
public class DefaultFeignExceptionHandler extends DefaultExceptionHandler{


    /**
     * Decode异常处理
     *
     * @param decodeException exception
     */
    @ExceptionHandler(value = {DecodeException.class})
    public ApiResult<Void> processException(DecodeException decodeException) {
        Throwable cause = decodeException.getCause();
        if(cause instanceof BusinessException businessException){
            log.warn("业务异常 {}", businessException.getMessage(), businessException);
            return ApiResult.fail(businessException.getMessage());
        }
        log.error(decodeException.getMessage(), decodeException);
        return ApiResult.fail(ApiResult.INTERNAL_FAIL_CODE, decodeException.getMessage());
    }


}



